import 'package:hockey/jzx_apps.dart';
import 'package:hockey/pages/jzx_login/widgets/jzx_pop_view.dart';
import 'package:hockey/services/jzx_user.dart';

class JzxLoginController extends GetxController {
  var isAgree = false.obs;

  bool _isAgreeJudge(VoidCallback? callback) {
    if (isAgree.isFalse) {
      // show dialog
      Get.dialog(
        JzxAgreePopView(
          onTap: () {
            isAgree.value = true;
            Get.back();
            callback?.call();
          },
        ),
        barrierColor: myAppColors.barrierColor,
      );
    }
    return isAgree.value;
  }

  void appleLoginAct() async {
    final state = _isAgreeJudge(() {
      appleLoginAct();
    });
    if (!state) {
      return;
    }

    JzxUserService.to.login(3);
    JzxLogPvManger.tracking(page: JzxLogPages.applelogin);
  }

  void quickLoginAct() {
    final state = _isAgreeJudge(() {
      quickLoginAct();
    });
    if (!state) {
      return;
    }

    JzxUserService.to.login(4);
    JzxLogPvManger.tracking(page: JzxLogPages.quicklogin);
  }
}
